<%--
  Created by IntelliJ IDEA.
  User: zzf
  Date: 2021/1/7
  Time: 16:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/public/header/permissionCommon.jspf" %>

<html>
<head>
    <title>飞行检查记录</title>

<body>
<div class="layui-layout-body">
 <div class="layui-layout layui-layout-admin">
    <!-- 头部和左侧导航-->
    <div id="header"></div>

    <!--右侧主体区域-->
    <div class="layui-body" style="margin:1%">



        <%--layui提供的表单附加工具栏编辑和删除    --%>
        <script type="text/html" id="EditAndDel">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="video">视频详情</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="hgdetail">护工信息</a>
        </script>
        <div class="layui-tab layui-tab-brief" >
            <ul class="layui-tab-title">
                <li id="searchList" class="layui-this" >飞检记录检索</li>
            </ul>
            <div class="layui-tab-content">
                <div >
                    <button  id="testbtn" class="layui-btn" style="margin-left: 20px">新增记录</button>
                </div>

                <%-- 筛选搜索表单模块--%>
                <div style="margin-top: 20px">
                    <form class="layui-form" id="searchForm"  method="post">
                        <div class="layui-form-item" >
                            <div class="layui-inline">
                                <label class="layui-form-label">管理员ID</label>
                                <div class="layui-input-inline">
                                    <input   id="adminID" type="text"  autocomplete="off" class="layui-input"  placeholder="在此输入管理员ID">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">管理员姓名</label>
                                <div class="layui-input-inline">
                                    <input   id="adminName" type="text"  autocomplete="off" class="layui-input"  placeholder="在此输入管理员姓名">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">检查时间</label>
                                <div class="layui-input-inline">
                                    <input name="check_time" id="checkdate"  type="text" autocomplete="off"  placeholder="请选择历史检查时间" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">护工ID</label>
                                <div class="layui-input-inline">
                                    <input  id="hgID" type="text"  autocomplete="off" class="layui-input"  placeholder="在此输入护工ID">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">护工姓名</label>
                                <div class="layui-input-inline">
                                    <input  id="hgName" type="text"  autocomplete="off" class="layui-input"  placeholder="在此输入护工姓名">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-inline">
                                    <label class="layui-form-label">检查结果</label>
                                    <div class="layui-input-inline">
                                        <select name="checkResult"  id="checkresult">
                                            <option value="">请选择</option>
                                            <option value="1">正常</option>
                                            <option value="2">异常</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>

                    <div  class="demotable" style="margin: 1%">
                        <button   id="save_btn" class="layui-btn layui-btn-sm"  data-type="reload">搜索</button>
                        <button   id="export" class="layui-btn layui-btn-sm" lay-event="export" >导出</button>
                    </div>
                </div>
            </div>
        </div>

        <%--用于导出的表格--%>
        <div style="display: none">
                <table id="data_export" >
                </table>
            </div>
        <%--飞行记录主体--%>
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li id="roleList" class="layui-this" >飞行检查记录</li>
                </ul>
                <div class="layui-tab-content" style="height: 100px;">
                    <div id="recordListDiv" class="layui-tab-item layui-show">
                        <table class="layui-table" id="recordList" lay-filter="test"  >

                        </table>

                    </div>
                </div>

        </div>
    </div>








    <!--底部-->
    <div id="footer"></div>
    <%--<script src="${webPath}/js/permission/auth/permList.js"></script>--%>
    <script>
        $("#header").load("${webPath}/publicPages/permission/fragments/header.jsp");
        $("#footer").load("${webPath}/publicPages/permission/fragments/footer.jsp");
    </script>



     <%--下方script代码可统一归入js文件中     --%>
     <%--输入检查日期组件    --%>
     <script>
         layui.use('laydate', function(){
             var laydate = layui.laydate;

             //执行一个laydate实例
             laydate.render({
                 elem: '#checkdate' //指定元素
             });
         });
     </script>

     <%--数据导出     --%>
     <script>

         $("#export").click(function () {
             layui.use('table', function () {
                 var table = layui.table;

                 var ins1 = table.render({
                     elem: "#data_export",
                     url: "/toTempCheck/export",
                     cols: [[
                         {field: 'admin_id', title: '管理员ID', width: 200, sort: true, fixed: 'left'}
                         , {field: 'admin_name', title: '管理员姓名', width: 140, sort: true}
                         , {field: 'hg_id', title: '护工ID', width: 200, sort: true}
                         , {field: 'hg_name', title: '护工姓名', width: 130, sort: true}
                         , {field: 'gender', title: '性别', width: 130, sort: true}
                         , {field: 'id_number', title: '身份证号', width: 130, sort: true}
                         , {field: 'sbdw', title: '所属单位', width: 130, sort: true}
                         , {field: 'rylb', title: '工种', width: 130, sort: true}
                         , {field: 'worklength', title: '工龄', width: 130, sort: true}
                         , {field: 'status', title: '在职状态', width: 130, sort: true}
                         , {field: 'phone_number', title: '联系电话', width: 130, sort: true}
                         , {field: 'check_time', title: '检查时间', width: 125, sort: true}
                         , {field: 'checkresult', title: '检查结果',
                             // templet:function(d){
                             //     if (d.checkresult===1){return "正常"}
                             //     else if(d.checkresult===2){return "异常"}
                             // },
                             width: 120, sort: true}

                         // ,{field: 'recordfile', title: '文件路径',width: 200}
                         , {field: 'checkdescribe', title: '描述', width: 300}
                         , {fixed: 'right', width: 327}
                     ]]
                     ,parseData: function(result){ //result 即为原始返回的数据
                         for(i=0;i<result.list.length;i++){
                             result.list[i].id_number+="\t";
                             if(result.list[i].checkresult==="1"){result.list[i].checkresult="正常"}
                             else if (result.list[i].checkresult==="2"){result.list[i].checkresult="异常"}
                         }
                         return {
                               "code": 0, //解析接口状态
                               "msg": "", //解析提示文本
                               "count": result.total, //解析数据长度
                               "data": result.list, //解析数据列表

                         }
                     }
                     ,done: function (res, curr, count) {
                         exportData = res.data;

                         table.exportFile(ins1.config.id, exportData,'csv');
                     }

                 })
             })
         })
     </script>

     <script>
         //layui内置数据表格调取
         layui.use('table', function(){
             var table = layui.table;

             //数据表格实例
             tableIns=table.render({
                 elem: '#recordList'
                 ,height: 500
                 ,url:'/toTempCheck/selectrecord' //数据接口
                 ,id:"showRecord"
                 ,where:{
                     admin_id:"",
                     admin_name:"",
                     hg_id:"",
                     hg_name:"",
                     check_time:"",
                     checkresult:""
                 }//额外参数

                 ,request:{
                     pageName: 'pn' //页码的参数名称，默认：page
                     ,limitName: 'limit' //每页数据量的参数名，默认：limit
                 }
                 ,parseData: function(result){ //result 即为原始返回的数据
                     return {
                         "code": 0, //解析接口状态
                         "msg": "", //解析提示文本
                         "count": result.total, //解析数据长度
                         "data": result.list, //解析数据列表

                     }
                 }
                 ,page:{
                     layout:['limit','count','prev','page','next','skip','limits']
                     ,limits:[10]

                 } //开启分页
                 ,cols: [[ //表头d.
                     {field: 'recordId', title: '编号', width:100, sort: true, fixed: 'left'}
                     ,{field: 'admin_id', title: '管理员ID', width:200,sort: true}
                     ,{field: 'admin_name', title: '管理员姓名', width:140,sort: true}
                     ,{field: 'hg_id', title: '护工ID', width:200,sort: true}
                     ,{field: 'hg_name', title: '护工姓名', width:130,sort: true}
                     ,{field: 'check_time', title: '检查时间', width:125,sort: true}
                     ,{field: 'checkresult', title: '检查结果',
                         templet:function(d){
                         if (d.checkresult===1){return "正常"}
                         else if(d.checkresult===2){return "异常"}

                         }, width:120, sort: true}

                     // ,{field: 'recordfile', title: '文件路径',width: 200}
                     ,{field: 'checkdescribe', title: '描述',width: 300}
                     ,{fixed:'right', title: '操作',toolbar:'#EditAndDel',width: 327}
                 ]]
             });

             var $=layui.$,active={
                 reload:function (){
                     var adminID=$("#adminID").val();
                     var adminName=$("#adminName").val();
                     var hgID=$("#hgID").val();
                     var hgName=$("#hgName").val();
                     var checkTime=$("#checkdate").val();
                     var checkResult=$("#checkresult").val();
                     console.log(checkResult)

                     table.reload('showRecord',{
                         url:"/toTempCheck/selectrecord",
                         page:{
                             curr:1
                         }
                         ,where: {
                             admin_id:adminID,
                             admin_name:adminName,
                             hg_id:hgID,
                             hg_name:hgName,
                             check_time:checkTime,
                             checkresult:checkResult
                         },
                         success:function (res){
                             console.log(res)
                         }

                     });
                 }
             };
             //监听搜索按钮
             $("#save_btn").on('click',function (){
                 var type=$(this).data('type');
                 active[type]?active[type].call(this):'';
             });






             //监听行工具事件
             table.on('tool(test)', function(obj){
                 //获取当前行数据信息
                 var data = obj.data;

                 //console.log(obj);
                 if(obj.event === 'del'){
                     layer.confirm('确认删除此条记录?', function(index){
                         var delid=data.recordId;

                         $.ajax({
                             url:"${webPath}/toTempCheck/record/"+delid,
                             type:"DELETE",
                             data: $("#newcheckForm").serialize(),
                             // contentType:false,
                             success:function (result){
                                 //alert(result.msg);
                                 // //当你在iframe页面关闭自身时
                                 // var index =parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                 // parent.layer.close(index); //再执行关闭
                                 tableIns.reload('showRecord',{
                                     url:"/toTempCheck/selectrecord",
                                 })

                             },
                             fail:function (result){
                                 alert(result.msg);
                             }



                         })

                         layer.close(index);

                     });
                 } else if(obj.event === 'edit'){


                     var temp;//暂存子弹窗页面的组件


                     //弹出信息框编辑
                     layer.open({
                         type: 2,
                         skin: 'layui-layer-rim', //加上边框
                         area: ['800px', '600px'], //宽高
                         title:"修改记录",
                         shade:0,//无遮罩
                         content:'/toTempCheck/toChangeCheck',//调到修改页面
                         success:function (layero,index){
                             //将此页面行数据传递到子页面
                             temp=$(layero).find("iframe").contents().find("#recordID");
                             temp.val(data.recordId);
                             temp=$(layero).find("iframe").contents().find("#adminID");
                             temp.val(data.admin_id);
                             temp=$(layero).find("iframe").contents().find("#adminName");
                             temp.val(data.admin_name);
                             temp=$(layero).find("iframe").contents().find("#hgID");
                             temp.val(data.hg_id);
                             temp=$(layero).find("iframe").contents().find("#hgName");
                             temp.val(data.hg_name);
                             temp=$(layero).find("iframe").contents().find("#checkdate");
                             temp.val(data.check_time);

                             temp=$(layero).find("iframe").contents().find("#checkresult");
                             temp.val(data.checkresult);

                             // if(data.checkresult==='1'){
                             //     temp=$(layero).find("iframe").contents().find("select option:");
                             //     temp.attr('selected',true);
                             // } else if(data.checkresult!=='1'){
                             //     temp=$(layero).find("iframe").contents().find("input[value='2']");
                             //     temp.attr('checked',true);
                             // }






                             //获取文件地址，填充进隐藏的input中
                             temp=$(layero).find("iframe").contents().find("#filePath");
                             temp.val(data.recordfile);

                             temp=$(layero).find("iframe").contents().find("#checkDescribe");
                             temp.val(data.checkdescribe);

                         },
                         end:function (){
                             tableIns.reload('showRecord',{
                                 url:"/toTempCheck/selectrecord",
                             })
                         }
                     })


                 }else if(obj.event === 'video'){
                     vUrl = "http://localhost:8080/"+data.recordfile;
                     console.log(vUrl);
                     var loadstr = '<video width="100%" height="100%"  controls="controls" autobuffer="autobuffer" autoplay="autoplay" loop="loop" '+'src='+vUrl+' >'+'</video>';
                     layer.open({
                         type: 1,
                         title: false,
                         area: ['740px', '500px'],
                         shade: [0.8, 'rgb(14, 16, 22)'],
                         skin: 'demo-class',
                         content: loadstr
                     });

                 }
                 else if(obj.event === 'hgdetail'){



                     layer.open({
                         type: 2,
                         skin: 'layui-layer-rim', //加上边框
                         area: ['800px', '600px'], //宽高
                         title:"护工信息",
                         shade:0,//无遮罩
                         content:'/toTempCheck/detail',//调到护工信息页面
                         success:function (layero){
                             temp=$(layero).find("iframe").contents().find("#ybID");
                             temp.val(data.hg_id);
                             console.log('当前护工的医保ID：',data.hg_id);
                             $.ajax({
                                 url:"/toTempCheck/detail/"+data.hg_id,//调到护工信息
                                 success:function (result){
                                     //console.log(result)
                                     temp=temp=$(layero).find("iframe").contents().find("#hgName");
                                     temp.val(result.name)
                                     temp=temp=$(layero).find("iframe").contents().find("#idNumber");
                                     temp.val(result.id_number)
                                     temp=temp=$(layero).find("iframe").contents().find("#Gender");
                                     temp.val(result.gender)
                                     temp=$(layero).find("iframe").contents().find("#SBDW");
                                     temp.val(result.sbdw)
                                     temp=$(layero).find("iframe").contents().find("#ryLb");
                                     temp.val(result.rylb)
                                     temp=$(layero).find("iframe").contents().find("#zyLevel");
                                     temp.val(result.zylevel)
                                     temp=$(layero).find("iframe").contents().find("#workLength");
                                     temp.val(result.worklength)
                                     temp=$(layero).find("iframe").contents().find("#Status");
                                     temp.val(result.status)
                                     temp=$(layero).find("iframe").contents().find("#phoneNumber");
                                     temp.val(result.phone_number)



                                 }
                             })



                         }
                     });

                 }
             });

         });
     </script>




     <%--    自动添加表单记录--%>
     <script type="text/javascript">
         var totalPages;
         <%--搜索功能--%>
         $(function (){
             //新增记录按钮弹出新增表单填写
             $("#testbtn").click(function (){
                 layer.open({
                     type: 2,
                     skin: 'layui-layer-rim', //加上边框
                     area: ['800px', '600px'], //宽高
                     title:"新增记录",
                     shade:0,//无遮罩
                     content:'/toTempCheck/toNewCheck',//调到新增页面
                     //刷新数据表格数据
                     end:function (){
                         tableIns.reload('showRecord',{
                             url:"/toTempCheck/selectrecord",
                         })
                     }
                 });
             })

         })
     </script>

   </div>
 </div>
</body>
</html>
